import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/Table';
import { companyList } from '../../companyManage/company/data/api';
import { goodsList } from '@apps/ant-bus/src/views/business/goods/goods/api';
import { payWayList } from '@apps/ant-bus/src/views/business/platformManage/payway/data/api';

export const columns: BasicColumn[] = [
  {
    title: '订单编号',
    dataIndex: 'orderNo',
    width: 160,
  },
  {
    title: '下单人主账号',
    dataIndex: 'mainAccount',
    width: 100,
  },
  {
    title: '下单人手机号',
    dataIndex: 'mobile',
    width: 100,
  },
  {
    title: '订单状态',
    dataIndex: 'orderStatus',
    width: 100,
    customRender: ({ record }: Recordable) => {
      const orderStatusArray = [
        { label: '待付款', value: '1' },
        { label: '已付款', value: '2' },
        { label: '已退款', value: '3' },
        { label: '申请退款中', value: '4' },
        { label: '已关闭', value: '5' },
        { label: '部分退款', value: 6 },
      ];
      const orderStatus: any = orderStatusArray.find(item => item.value == record.orderStatus);
      if (orderStatus) {
        return orderStatus.label;
      }
      return '';
    },
  },
  {
    title: '支付类型',
    dataIndex: 'payType',
    width: 100,
    customRender: ({ record }: Recordable) => {
      const payTypeArray = [
        { label: '迅联微信', value: 'PAY_WX' },
        { label: '银联微信', value: 'PAY_WX_YINLIAN' },
        { label: '农业银行微信', value: 'PAY_WX_NONGYE' },
        { label: '富友微信', value: 'PAY_WX_FUIOU' },
        { label: '富友微信小程序', value: 'PAY_WX_FUIOU_MINI' },
        { label: '交通银行微信', value: 'PAY_WX_JIAOTONG' },
        { label: '易宝微信', value: 'PAY_WX_YIBAO' },
        { label: '线下', value: 'PAY_UNDERLINE' },
        { label: '公司余额', value: 'PAY_COMPANY_BALANCE' },
        { label: '扫码支付', value: 'PAY_QRCODE' },
      ];
      const payType: any = payTypeArray.find(item => item.value == record.payType);
      if (payType) {
        return payType.label;
      }
      return '';
    },
  },
  {
    title: '支付参数',
    dataIndex: 'payParamName',
    width: 100,
  },
  {
    title: '订单总金额',
    dataIndex: 'totalPrice',
    width: 100,
  },
  {
    title: '退款金额',
    dataIndex: 'refundAmount',
    width: 100,
  },
  {
    title: '线下支付收款',
    dataIndex: 'isCheck',
    width: 140,
    align: 'center',
    customRender: ({ record }: Recordable) => {
      const isCheckArray = [
        { label: '已确认', value: 1 },
        { label: '未确认', value: 2 },
      ];
      const isCheck: any = isCheckArray.find(item => item.value == record.isCheck);
      if (isCheck) {
        return isCheck.label;
      }
      return '';
    },
  },
  {
    title: '线下支付名称',
    dataIndex: 'paywayName',
    width: 100,
  },
  {
    title: '销售',
    dataIndex: 'employeeName',
    width: 100,
  },
  {
    title: '创建日期',
    dataIndex: 'createTime',
    width: 150,
  },
  {
    title: '用户备注',
    dataIndex: 'remark',
    width: 100,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'orderNo',
    label: '订单编号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'mainAccount',
    label: '主账号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'mobile',
    label: '手机号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'companyId',
    label: '合作企业',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: {
      api: companyList,
      params: {},
      labelField: 'companyName',
      valueField: 'companyId',
      immediate: true,
    },
  },
  {
    field: 'orderStatus',
    label: '订单状态',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '待付款', value: 1 },
        { label: '已付款', value: 2 },
        { label: '已退款', value: 3 },
        { label: '申请退款中', value: 4 },
        { label: '已关闭', value: 5 },
        { label: '部分退款', value: 6 },
      ],
    },
  },
  {
    field: 'payType',
    label: '支付类型',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '迅联微信', value: 'PAY_WX' },
        { label: '易宝微信', value: 'PAY_WX_YIBAO' },
        { label: '银联微信', value: 'PAY_WX_YINLIAN' },
        { label: '农业银行微信', value: 'PAY_WX_NONGYE' },
        { label: '富友微信', value: 'PAY_WX_FUIOU' },
        { label: '富友微信小程序', value: 'PAY_WX_FUIOU_MINI' },
        { label: '交通银行微信', value: 'PAY_WX_JIAOTONG' },
        { label: '线下支付', value: 'PAY_UNDERLINE' },
        { label: '公司余额', value: 'PAY_COMPANY_BALANCE' },
        { label: '扫码支付', value: 'PAY_QRCODE' },
      ],
    },
  },
  {
    field: 'paywayId',
    label: '线下支付',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: {
      api: payWayList,
      params: {},
      labelField: 'paywayName',
      valueField: 'paywayId',
      immediate: true,
    },
  },
  {
    field: 'startDate',
    label: '开始日期',
    component: 'DatePicker',
    colProps: { span: 4 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    field: 'endDate',
    label: '结束日期',
    component: 'DatePicker',
    colProps: { span: 4 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '商品',
    field: 'goodsId',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: goodsList,
      labelField: 'goodsName',
      valueField: 'goodsId',
      immediate: true,
      showSearch: true,
    },
  },
  {
    label: '支付类型',
    field: 'payType',
    component: 'Select',
    required: true,
    defaultValue: 'PAY_UNDERLINE',
    componentProps: {
      options: [{ label: '线下支付', value: 'PAY_UNDERLINE' }],
    },
  },
  {
    label: '线下支付',
    field: 'paywayId',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: payWayList,
      labelField: 'paywayName',
      valueField: 'paywayId',
      immediate: true,
      showSearch: true,
    },
  },
  {
    label: '购物方式',
    field: 'buySource',
    component: 'Select',
    required: true,
    defaultValue: 1,
    componentProps: {
      options: [{ label: '非购物车', value: 1 }],
    },
  },
  {
    label: '订单金额',
    field: 'totalPrice',
    component: 'InputNumber',
    required: true,
  },
  {
    label: '订单来源',
    field: 'sourceType',
    component: 'Input',
    defaultValue: 1,
    required: false,
    show: false,
  },
  {
    label: '用户备注',
    field: 'remark',
    component: 'InputTextArea',
    required: false,
  },
];
